package cn.koala.key.common.feign;

import cn.koala.key.configure.apollo.ApolloKeyManagementAdminConfig;
import cn.seed.common.core.SpringContext;
import feign.Feign;
import org.springframework.context.ApplicationContext;

/**
 * fegin网络请求工具类
 *
 * @author lixiao
 */
public class FeignUtils {

    private static String baseUrl = ApolloKeyManagementAdminConfig.getKeyapi();

    public static <T extends BaseApi> T getHttpApi(Class<T> api, String url) {
        ApplicationContext applicationContext = SpringContext.getApplicationContext();
        return applicationContext.getBean(Feign.Builder.class).target(api, url);
    }

    public static <T extends BaseApi> T getHttpApi(Class<T> api) {
        return getHttpApi(api, baseUrl);
    }
}
